package com.cg.design.graphicdesignpattern.mediator;

import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

/**
 * 表示单选按钮的类，实现了Colleague类和java.awt.event.ItemListener类，继承了java.awt.Checkbox类
 *
 * @program: LeetCode->ColleagueCheckbox
 * @description: 表示单选按钮的类，实现了Colleague类和java.awt.event.ItemListener类，继承了java.awt.Checkbox类
 * @author: cg
 * @create: 2022-03-28 10:47
 **/
public class ColleagueCheckbox extends Checkbox implements ItemListener, Colleague {

    /**
     * 中介者
     */
    private Mediator mediator;

    public ColleagueCheckbox(String caption, CheckboxGroup group, boolean state) {
        super(caption, group, state);
    }

    @Override
    public void setMediator(Mediator mediator) {
        // 保存Mediator
        this.mediator = mediator;
    }

    @Override
    public void setColleagueEnabled(boolean enabled) {
        // 根据中介者的指令下达启用/禁用
        setEnabled(enabled);
    }

    @Override
    public void itemStateChanged(ItemEvent e) {
        // 当文字发生变化时通知Mediator
        mediator.colleagueChanged();
    }
}
